Skip to contentSkip to conversation

balena-engine: add recipe

PATCH Superseded Maciej Pijanowski 2 participants 3 messages Nov 24, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 balena-engine: add recipe

As explained in [1], I have created the balena-engine recipe which could be used in "regular" Yocto/OE builds (outside of the balenaOS). The recipe is mostly a copy of the original recipe from meta-balena, stripped from the balenaOS-specific parts so it can be compiled and build outside of it. This recipe was tested at build and runtime on the dunfell release on two targets: RPi4 and qemux86-64.

[1] https://lists.yoctoproject.org/g/meta-virtualization/message/5913

---
 ...dcoded-CC-on-cross-compile-docker-ce.patch |  60 +++++++
 .../balena-engine/balena-tmpfiles.conf        |   2 +
 .../balena-engine/balena-engine_git.bb        | 159 ++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
 create mode 100644 recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
 create mode 100644 recipes-containers/balena-engine/balena-engine_git.bb
recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch new file +60 -0
new file mode 100644
index 000000000000..0f257f1bd964
@@ -0,0 +1,60 @@
+From 1263fdb50a540e9db742694b7cee08284ad986d0 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <[email protected]>
+Date: Wed, 17 Jul 2019 17:34:04 +0800
+Subject: [PATCH] imporve hardcoded CC on cross compile
+
+Since commit applied in moby [61a3285 Support cross-compile for arm]
+it hardcoded var-CC to support cross-compile for arm
+
+Correct it with "${parameter:-word}" format, it is helpful for user
+define toolchains
+
+(Use Default Values.  If parameter is unset or null, the expansion of
+word is substituted.  Otherwise, the value of parameter is substituted.)
+
+Upstream-Status: Submitted [https://github.com/moby/moby/pull/39546]
+
+Signed-off-by: Hongxu Jia <[email protected]>
+---
+ hack/make/.binary | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/import/hack/make/.binary b/src/import/hack/make/.binary
+index 53de6749e5..66f4ca05f3 100644
+--- a/src/import/hack/make/.binary
++++ b/src/import/hack/make/.binary
+@@ -44,27 +44,27 @@ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARC
+	# must be cross-compiling!
+	case "$(go env GOOS)/$(go env GOARCH)" in
+		windows/amd64)
+-			export CC=x86_64-w64-mingw32-gcc
++			export CC="${CC:-x86_64-w64-mingw32-gcc}"
+			export CGO_ENABLED=1
+			;;
+		linux/arm)
+			case "${GOARM}" in
+			5|"")
+-				export CC=arm-linux-gnueabi-gcc
++				export CC="${CC:-arm-linux-gnueabi-gcc}"
+				export CGO_ENABLED=1
+				;;
+			7)
+-				export CC=arm-linux-gnueabihf-gcc
++				export CC="${CC:-arm-linux-gnueabihf-gcc}"
+				export CGO_ENABLED=1
+				;;
+			esac
+			;;
+		linux/arm64)
+-			export CC=aarch64-linux-gnu-gcc
++			export CC="${CC:-aarch64-linux-gnu-gcc}"
+			export CGO_ENABLED=1
+			;;
+		linux/amd64)
+-			export CC=x86_64-linux-gnu-gcc
++			export CC="${CC:-x86_64-linux-gnu-gcc}"
+			export CGO_ENABLED=1
+			;;
+	esac
+--
+2.23.0
recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf new file +2 -0
new file mode 100644
index 000000000000..548a25d3ae49
@@ -0,0 +1,2 @@
+L	/run/docker.pid	-	-	-	-	/run/balena-engine.pid
+L	/run/balena.pid	-	-	-	-	/run/balena-engine.pid
recipes-containers/balena-engine/balena-engine_git.bb new file +159 -0

159 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Maciej Pijanowski

As explained in [1], I have created the balena-engine recipe which could be used in "regular" Yocto/OE builds (outside of the balenaOS). The recipe is mostly a copy of the original recipe from meta-balena, stripped from the balenaOS-specific parts so it can be compiled and build outside of it. This recipe was tested at build and runtime on the dunfell release on two targets: RPi4 and qemux86-64.

Thanks for the contribution, it is most appreciated. The recipe unfortunately raises some concerns .. and something that we can work through.

Quoted 126 lines

[1] https://lists.yoctoproject.org/g/meta-virtualization/message/5913

---
 ...dcoded-CC-on-cross-compile-docker-ce.patch |  60 +++++++
 .../balena-engine/balena-tmpfiles.conf        |   2 +
 .../balena-engine/balena-engine_git.bb        | 159 ++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644
recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
 create mode 100644
recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
 create mode 100644 recipes-containers/balena-engine/balena-engine_git.bb

diff --git a/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch new file mode 100644
index 000000000000..0f257f1bd964
--- /dev/null
+++
b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch

recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch new file +26 -0
@@ -0,0 +1,60 @@
+From 1263fdb50a540e9db742694b7cee08284ad986d0 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <[email protected]>
+Date: Wed, 17 Jul 2019 17:34:04 +0800
+Subject: [PATCH] imporve hardcoded CC on cross compile
+
+Since commit applied in moby [61a3285 Support cross-compile for arm]
+it hardcoded var-CC to support cross-compile for arm
+
+Correct it with "${parameter:-word}" format, it is helpful for user
+define toolchains
+
+(Use Default Values.  If parameter is unset or null, the expansion of
+word is substituted.  Otherwise, the value of parameter is substituted.)
+
+Upstream-Status: Submitted [https://github.com/moby/moby/pull/39546]
+
+Signed-off-by: Hongxu Jia <[email protected]>
+---
+ hack/make/.binary | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/import/hack/make/.binary b/src/import/hack/make/.binary
+index 53de6749e5..66f4ca05f3 100644
+--- a/src/import/hack/make/.binary
++++ b/src/import/hack/make/.binary
+@@ -44,27 +44,27 @@ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env

GOHOSTOS)/$(go env GOHOSTARC

recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch new file +34 -0
+       # must be cross-compiling!
+       case "$(go env GOOS)/$(go env GOARCH)" in
+               windows/amd64)
+-                      export CC=x86_64-w64-mingw32-gcc
++                      export CC="${CC:-x86_64-w64-mingw32-gcc}"
+                       export CGO_ENABLED=1
+                       ;;
+               linux/arm)
+                       case "${GOARM}" in
+                       5|"")
+-                              export CC=arm-linux-gnueabi-gcc
++                              export CC="${CC:-arm-linux-gnueabi-gcc}"
+                               export CGO_ENABLED=1
+                               ;;
+                       7)
+-                              export CC=arm-linux-gnueabihf-gcc
++                              export CC="${CC:-arm-linux-gnueabihf-gcc}"
+                               export CGO_ENABLED=1
+                               ;;
+                       esac
+                       ;;
+               linux/arm64)
+-                      export CC=aarch64-linux-gnu-gcc
++                      export CC="${CC:-aarch64-linux-gnu-gcc}"
+                       export CGO_ENABLED=1
+                       ;;
+               linux/amd64)
+-                      export CC=x86_64-linux-gnu-gcc
++                      export CC="${CC:-x86_64-linux-gnu-gcc}"
+                       export CGO_ENABLED=1
+                       ;;
+       esac
+--
+2.23.0

diff --git a/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf b/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf new file mode 100644
index 000000000000..548a25d3ae49

recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf new file +2 -0
@@ -0,0 +1,2 @@
+L      /run/docker.pid -       -       -       -
 /run/balena-engine.pid
+L      /run/balena.pid -       -       -       -
 /run/balena-engine.pid
recipes-containers/balena-engine/balena-engine_git.bb new file +3 -0
new file mode 100644
index 000000000000..5d78dc02350f
@@ -0,0 +1,159 @@
+HOMEPAGE = "https://www.balena.io/"
+SUMMARY = "A Moby-based container engine for IoT"
+DESCRIPTION = "Balena is a new container engine purpose-built for

embedded \
+and IoT use cases and compatible with Docker containers. Based on Docker’s \

recipes-containers/balena-engine/balena-engine_git.bb new file +6 -0
+Moby Project, balena supports container deltas for 10-70x more efficient \
+bandwidth usage, has 3.5x smaller binaries, uses RAM and storage more \
+conservatively, and focuses on atomicity and durability of container \
+pulling."
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM =

"file://src/import/LICENSE;md5=4859e97a9c7780e77972d989f0823f28"

recipes-containers/balena-engine/balena-engine_git.bb new file +9 -0
+
+inherit systemd go pkgconfig useradd
+
+BALENA_VERSION = "19.03.13-dev"
+BALENA_BRANCH= "master"
+
+SRCREV = "074a481789174b4b6fd2d706086e8ffceb72e924"
+SRC_URI = "\
+       git://
Quoted 5 lines

github.com/balena-os/balena-engine.git;branch=${BALENA_BRANCH};destsuffix=git/src/import
<http://github.com/balena-os/balena-engine.git;branch=$%7BBALENA_BRANCH%7D;destsuffix=git/src/import>
\
+ file://0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch \

The fact that we have to duplicate that patch, exposes an issue.

It comes down to the fact that we already have containerd, moby, runc, etc, recipes.

Having vendored copies for all of the engine variants is a problem, and one what I'm looking to solve. I can help on that front, but it won't be until after I've finished getting k3s working and merged.

See more specific comments below.

Quoted 22 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +19 -0
+        file://balena-tmpfiles.conf \
+       "
+
+S = "${WORKDIR}/git"
+
+PV = "${BALENA_VERSION}+git${SRCREV}"
+
+SECURITY_CFLAGS = "${SECURITY_NOPIE_CFLAGS}"
+SECURITY_LDFLAGS = ""
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = "balena-engine.service balena-engine.socket"
+GO_IMPORT = "import"
+USERADD_PACKAGES = "${PN}"
+GROUPADD_PARAM_${PN} = "-r balena-engine"
+
+DEPENDS_append_class-target = " systemd"
+RDEPENDS_${PN}_class-target = "curl util-linux iptables tini systemd bash"
+RRECOMMENDS_${PN} += "kernel-module-nf-nat kernel-module-br-netfilter

kernel-module-nf-conntrack-netlink kernel-module-xt-masquerade kernel-module-xt-addrtype"

recipes-containers/balena-engine/balena-engine_git.bb

Quoted 2 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +2 -0
+
+# oe-meta-go recipes try to build go-cross-native

oe-meta-go shouldn't be relevant anymore .. neither should those _remove's.

recipes-containers/balena-engine/balena-engine_git.bb line 48

Quoted 8 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +7 -0
+DEPENDS_remove_class-native = "go-cross-native"
+DEPENDS_append_class-native = " go-native"
+
+INSANE_SKIP_${PN} += "already-stripped"
+
+FILES_${PN} += " \
+       /lib/systemd/system/* \

/lib shouldn't be hardcoded.

+ /home/root \

Quoted 1 line

neither should /home/root/

Quoted 33 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +32 -0
+       /boot/init \
+       /boot/storage-driver \
+       ${localstatedir} \
+       "
+
+DOCKER_PKG="github.com/docker/docker"
+
+# By default no extra LDFLAGS needed when compiling mobynit
+MOBYNIT_EXTRA_LDFLAGS ??= ""
+
+do_configure[noexec] = "1"
+
+do_compile() {
+       export PATH=${STAGING_BINDIR_NATIVE}/${HOST_SYS}:$PATH
+
+       export GOCACHE="${B}/.cache"
+       export GOHOSTOS="linux"
+       export GOOS="linux"
+       case "${TARGET_ARCH}" in
+               x86_64)
+                       GOARCH=amd64
+                       ;;
+               i586|i686)
+                       GOARCH=386
+                       ;;
+               arm)
+                       GOARCH=${TARGET_ARCH}
+                       case "${TUNE_PKGARCH}" in
+                               cortexa*)
+                                       export GOARM=7
+                                       ;;
+                       esac

recipes-containers/balena-engine/balena-engine_git.bb line 91

Quoted 10 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +10 -0
+                       ;;
+               aarch64)
+                       # ARM64 is invalid for Go 1.4
+                       GOARCH=arm64
+               ;;
+               *)
+                       GOARCH="${TARGET_ARCH}"
+               ;;
+       esac
+       export GOARCH

There are already classes that deal with the arch mapping, it doesn't belong in individual recipes.

+

Quoted 19 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +8 -0
+       # Set GOPATH. See 'PACKAGERS.md'. Don't rely on
+       # docker to download its dependencies but rather
+       # use dependencies packaged independently.
+       cd ${S}/src/import
+       rm -rf .gopath
+       mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
+       ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
+       export

GOPATH="${S}/src/import/.gopath:${S}/src/import/vendor:${STAGING_DIR_TARGET}/${prefix}/local/go"

recipes-containers/balena-engine/balena-engine_git.bb new file +10 -0
+
+       export CGO_ENABLED="1"
+
+       # Pass the needed cflags/ldflags so that cgo
+       # can find the needed headers files and libraries
+       export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
+       export CGO_LDFLAGS="${LDFLAGS}  --sysroot=${STAGING_DIR_TARGET}"
+
+       export DOCKER_GITCOMMIT="${SRCREV}"
+       export DOCKER_BUILDTAGS="no_buildkit no_btrfs no_cri no_devmapper
Quoted 3 lines

no_zfs exclude_disk_quota exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_zfs"

As we've already solved in the other docker/moby recipes, we any setting of buildtags needs to be by variable, so it can be overriden by bbappends, etc.

recipes-containers/balena-engine/balena-engine_git.bb line 113

Quoted 4 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +3 -0
+       export DOCKER_LDFLAGS="-s"
+
+       VERSION=${BALENA_VERSION} ./hack/make.sh dynbinary-balena

And here we are with the repeated moby build infrastructure.

I am curious as to why mainline moby won't work for this.

Quoted 6 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +4 -0
+
+       # Compile mobynit
+       cd .gopath/src/"${DOCKER_PKG}"/cmd/mobynit
+       go build -ldflags '-extldflags "-static ${MOBYNIT_EXTRA_LDFLAGS}"'

.

This shouldn't be using 'go' directly, at the least, it should be using the variables as defined in the go classes.

But again, this is solving and duplicating all the fixes that we've had to do over time in the existing moby recipe. .. this is less than ideal. and anything that we haven't solved there, we should actually be fixing there.

Quoted 18 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +6 -0
+       cd -
+}
+
+do_install() {
+       mkdir -p ${D}/${bindir}
+       install -m 0755

${S}/src/import/bundles/dynbinary-balena/balena-engine ${D}/${bindir}/balena-engine

recipes-containers/balena-engine/balena-engine_git.bb new file +2 -0
+       # install -d ${D}/boot
+       # install -m 0755 ${S}/src/import/cmd/mobynit/mobynit

${D}/boot/init

recipes-containers/balena-engine/balena-engine_git.bb new file +6 -0
+       # echo ${BALENA_STORAGE} > ${D}/boot/storage-driver
+
+       ln -sf balena-engine ${D}/${bindir}/balena
+       ln -sf balena-engine ${D}/${bindir}/balenad
+       ln -sf balena-engine ${D}/${bindir}/balena-containerd
+       ln -sf balena-engine ${D}/${bindir}/balena-containerd-shim

recipes-containers/balena-engine/balena-engine_git.bb line 141

Quoted 10 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +10 -0
+       ln -sf balena-engine ${D}/${bindir}/balena-containerd-ctr
+       ln -sf balena-engine ${D}/${bindir}/balena-runc
+       ln -sf balena-engine ${D}/${bindir}/balena-proxy
+
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-daemon
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd-shim
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd-ctr
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-runc
+       ln -sf balena-engine ${D}/${bindir}/balena-engine-proxy

Outside of the branding, what's the difference between these binaries and when we build the upstream project variants ?

Quoted 9 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +3 -0
+
+       install -d ${D}${systemd_unitdir}/system
+       install -m 0644

${S}/src/import/contrib/init/systemd/balena-engine.socket ${D}/${systemd_unitdir}/system
+ install -m 0644
${S}/src/import/contrib/init/systemd/balena-engine.service ${D}/${systemd_unitdir}/system

The init system is variable, and should be checked before attempting to install services.

recipes-containers/balena-engine/balena-engine_git.bb line 149

Quoted 5 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +4 -0
+
+       install -d ${D}/home/root/.docker
+       ln -sf .docker ${D}/home/root/.balena
+       ln -sf .docker ${D}/home/root/.balena-engine

As mentioned above /home/room, shouldn't be hardcoded.

recipes-containers/balena-engine/balena-engine_git.bb

Quoted 3 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +2 -0
+
+       install -d ${D}${localstatedir}/lib/docker

Now we are polluting namespaces. A balena recipe making directories called "docker". This is the issue I had with k3s and CNI, and my concern about all the vendored versions we are getting in the container recipes.

recipes-containers/balena-engine/balena-engine_git.bb line 159

Quoted 10 lines
recipes-containers/balena-engine/balena-engine_git.bb new file +5 -0
+       ln -sf docker ${D}${localstatedir}/lib/balena
+       ln -sf docker ${D}${localstatedir}/lib/balena-engine
+
+       install -d ${D}${sysconfdir}/tmpfiles.d
+       install -m 0644 ${WORKDIR}/balena-tmpfiles.conf

${D}${sysconfdir}/tmpfiles.d/

recipes-containers/balena-engine/balena-engine_git.bb new file +3 -0
+}
+
+BBCLASSEXTEND = " native"

Where is this being used natively ?

Bruce

Quoted 7 lines

--
2.25.1

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end
- "Use the force Harry" - Gandalf, Star Trek II
#2 lore raw
Quoted 169 lines · Bruce Ashfield

On Tue, Nov 24, 2020 at 12:20 PM Maciej Pijanowski <[email protected] <mailto:[email protected]>> wrote:

As explained in [1], I have created the balena-engine recipe which could be
used in "regular" Yocto/OE builds (outside of the balenaOS). The recipe is mostly a copy of the original recipe from meta-balena, stripped from the balenaOS-specific parts so it can be compiled and build outside of it. This recipe was tested at build and runtime on the dunfell release on two targets: RPi4 and qemux86-64.

Thanks for the contribution, it is most appreciated. The recipe unfortunately raises some concerns ..and something that we can work through.

    [1] https://lists.yoctoproject.org/g/meta-virtualization/message/5913

    Signed-off-by: Maciej Pijanowski <[email protected]
    <mailto:[email protected]>>
    ---
     ...dcoded-CC-on-cross-compile-docker-ce.patch |  60 +++++++
     .../balena-engine/balena-tmpfiles.conf        |   2 +
     .../balena-engine/balena-engine_git.bb
    <http://balena-engine_git.bb>        | 159 ++++++++++++++++++
     3 files changed, 221 insertions(+)
     create mode 100644
    recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
     create mode 100644
    recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
     create mode 100644
    recipes-containers/balena-engine/balena-engine_git.bb
    <http://balena-engine_git.bb>

    diff --git
    a/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
    b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
    new file mode 100644
    index 000000000000..0f257f1bd964
    --- /dev/null
    +++
    b/recipes-containers/balena-engine/balena-engine/0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch
    @@ -0,0 +1,60 @@
    +From 1263fdb50a540e9db742694b7cee08284ad986d0 Mon Sep 17 00:00:00
    2001
    +From: Hongxu Jia <[email protected]
    <mailto:[email protected]>>
    +Date: Wed, 17 Jul 2019 17:34:04 +0800
    +Subject: [PATCH] imporve hardcoded CC on cross compile
    +
    +Since commit applied in moby [61a3285 Support cross-compile for arm]
    +it hardcoded var-CC to support cross-compile for arm
    +
    +Correct it with "${parameter:-word}" format, it is helpful for user
    +define toolchains
    +
    +(Use Default Values.  If parameter is unset or null, the expansion of
    +word is substituted.  Otherwise, the value of parameter is
    substituted.)
    +
    +Upstream-Status: Submitted [https://github.com/moby/moby/pull/39546]
    +
    +Signed-off-by: Hongxu Jia <[email protected]
    <mailto:[email protected]>>
    +---
    + hack/make/.binary | 10 +++++-----
    + 1 file changed, 5 insertions(+), 5 deletions(-)
    +
    +diff --git a/src/import/hack/make/.binary
    b/src/import/hack/make/.binary
    +index 53de6749e5..66f4ca05f3 100644
    +--- a/src/import/hack/make/.binary
    ++++ b/src/import/hack/make/.binary
    +@@ -44,27 +44,27 @@ if [ "$(go env GOOS)/$(go env GOARCH)" !=
    "$(go env GOHOSTOS)/$(go env GOHOSTARC
    +       # must be cross-compiling!
    +       case "$(go env GOOS)/$(go env GOARCH)" in
    +               windows/amd64)
    +-                      export CC=x86_64-w64-mingw32-gcc
    ++                      export CC="${CC:-x86_64-w64-mingw32-gcc}"
    +                       export CGO_ENABLED=1
    +                       ;;
    +               linux/arm)
    +                       case "${GOARM}" in
    +                       5|"")
    +-                              export CC=arm-linux-gnueabi-gcc
    ++                              export
    CC="${CC:-arm-linux-gnueabi-gcc}"
    +                               export CGO_ENABLED=1
    +                               ;;
    +                       7)
    +-                              export CC=arm-linux-gnueabihf-gcc
    ++                              export
    CC="${CC:-arm-linux-gnueabihf-gcc}"
    +                               export CGO_ENABLED=1
    +                               ;;
    +                       esac
    +                       ;;
    +               linux/arm64)
    +-                      export CC=aarch64-linux-gnu-gcc
    ++                      export CC="${CC:-aarch64-linux-gnu-gcc}"
    +                       export CGO_ENABLED=1
    +                       ;;
    +               linux/amd64)
    +-                      export CC=x86_64-linux-gnu-gcc
    ++                      export CC="${CC:-x86_64-linux-gnu-gcc}"
    +                       export CGO_ENABLED=1
    +                       ;;
    +       esac
    +--
    +2.23.0
    diff --git
    a/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
    b/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
    new file mode 100644
    index 000000000000..548a25d3ae49
    --- /dev/null
    +++
    b/recipes-containers/balena-engine/balena-engine/balena-tmpfiles.conf
    @@ -0,0 +1,2 @@
    +L      /run/docker.pid -       -       -       -     
     /run/balena-engine.pid
    +L      /run/balena.pid -       -       -       -     
     /run/balena-engine.pid
    diff --git a/recipes-containers/balena-engine/balena-engine_git.bb
    <http://balena-engine_git.bb>
    b/recipes-containers/balena-engine/balena-engine_git.bb
    <http://balena-engine_git.bb>
    new file mode 100644
    index 000000000000..5d78dc02350f
    --- /dev/null
    +++ b/recipes-containers/balena-engine/balena-engine_git.bb
    <http://balena-engine_git.bb>
    @@ -0,0 +1,159 @@
    +HOMEPAGE = "https://www.balena.io/"
    +SUMMARY = "A Moby-based container engine for IoT"
    +DESCRIPTION = "Balena is a new container engine purpose-built for
    embedded \
    +and IoT use cases and compatible with Docker containers. Based on
    Docker’s \
    +Moby Project, balena supports container deltas for 10-70x more
    efficient \
    +bandwidth usage, has 3.5x smaller binaries, uses RAM and storage
    more \
    +conservatively, and focuses on atomicity and durability of
    container \
    +pulling."
    +LICENSE = "Apache-2.0"
    +LIC_FILES_CHKSUM =
    "file://src/import/LICENSE;md5=4859e97a9c7780e77972d989f0823f28"
    +
    +inherit systemd go pkgconfig useradd
    +
    +BALENA_VERSION = "19.03.13-dev"
    +BALENA_BRANCH= "master"
    +
    +SRCREV = "074a481789174b4b6fd2d706086e8ffceb72e924"
    +SRC_URI = "\
    +     
     git://github.com/balena-os/balena-engine.git;branch=${BALENA_BRANCH};destsuffix=git/src/import
    <http://github.com/balena-os/balena-engine.git;branch=$%7BBALENA_BRANCH%7D;destsuffix=git/src/import>
    \
    +     
     file://0001-imporve-hardcoded-CC-on-cross-compile-docker-ce.patch \
Quoted 8 lines

The fact that we have to duplicate that patch, exposes an issue.

It comes down to the fact that we already have containerd, moby, runc, etc, recipes.

Having vendored copies for all of the engine variants is a problem, and one what I'm looking to solve.  I can help on that front, but it won't be until after I've finished getting k3s working and merged.

Ok. I will start with the simpler fixes for v2 and we will go back to that.

Quoted 133 lines

See more specific comments below.

    +        file://balena-tmpfiles.conf \
    +       "
    +
    +S = "${WORKDIR}/git"
    +
    +PV = "${BALENA_VERSION}+git${SRCREV}"
    +
    +SECURITY_CFLAGS = "${SECURITY_NOPIE_CFLAGS}"
    +SECURITY_LDFLAGS = ""
    +
    +SYSTEMD_PACKAGES = "${PN}"
    +SYSTEMD_SERVICE_${PN} = "balena-engine.service balena-engine.socket"
    +GO_IMPORT = "import"
    +USERADD_PACKAGES = "${PN}"
    +GROUPADD_PARAM_${PN} = "-r balena-engine"
    +
    +DEPENDS_append_class-target = " systemd"
    +RDEPENDS_${PN}_class-target = "curl util-linux iptables tini
    systemd bash"
    +RRECOMMENDS_${PN} += "kernel-module-nf-nat
    kernel-module-br-netfilter kernel-module-nf-conntrack-netlink
    kernel-module-xt-masquerade kernel-module-xt-addrtype"
    +
    +# oe-meta-go recipes try to build go-cross-native

oe-meta-go shouldn't be relevant anymore .. neither should those _remove's.

    +DEPENDS_remove_class-native = "go-cross-native"
    +DEPENDS_append_class-native = " go-native"
    +
    +INSANE_SKIP_${PN} += "already-stripped"
    +
    +FILES_${PN} += " \
    +       /lib/systemd/system/* \

/lib shouldn't be hardcoded.

    +       /home/root \

neither should /home/root/

    +       /boot/init \
    +       /boot/storage-driver \
    +       ${localstatedir} \
    +       "
    +
    +DOCKER_PKG="github.com/docker/docker
    <http://github.com/docker/docker>"
    +
    +# By default no extra LDFLAGS needed when compiling mobynit
    +MOBYNIT_EXTRA_LDFLAGS ??= ""
    +
    +do_configure[noexec] = "1"
    +
    +do_compile() {
    +       export PATH=${STAGING_BINDIR_NATIVE}/${HOST_SYS}:$PATH
    +
    +       export GOCACHE="${B}/.cache"
    +       export GOHOSTOS="linux"
    +       export GOOS="linux"
    +       case "${TARGET_ARCH}" in
    +               x86_64)
    +                       GOARCH=amd64
    +                       ;;
    +               i586|i686)
    +                       GOARCH=386
    +                       ;;
    +               arm)
    +                       GOARCH=${TARGET_ARCH}
    +                       case "${TUNE_PKGARCH}" in
    +                               cortexa*)
    +                                       export GOARM=7
    +                                       ;;
    +                       esac
    +                       ;;
    +               aarch64)
    +                       # ARM64 is invalid for Go 1.4
    +                       GOARCH=arm64
    +               ;;
    +               *)
    +                       GOARCH="${TARGET_ARCH}"
    +               ;;
    +       esac
    +       export GOARCH

There are already classes that deal with the arch mapping, it doesn't belong in individual recipes.

    +
    +       # Set GOPATH. See 'PACKAGERS.md'. Don't rely on
    +       # docker to download its dependencies but rather
    +       # use dependencies packaged independently.
    +       cd ${S}/src/import
    +       rm -rf .gopath
    +       mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")"
    +       ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}"
    +       export
    GOPATH="${S}/src/import/.gopath:${S}/src/import/vendor:${STAGING_DIR_TARGET}/${prefix}/local/go"
    +
    +       export CGO_ENABLED="1"
    +
    +       # Pass the needed cflags/ldflags so that cgo
    +       # can find the needed headers files and libraries
    +       export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
    +       export CGO_LDFLAGS="${LDFLAGS} 
    --sysroot=${STAGING_DIR_TARGET}"
    +
    +       export DOCKER_GITCOMMIT="${SRCREV}"
    +       export DOCKER_BUILDTAGS="no_buildkit no_btrfs no_cri
    no_devmapper no_zfs exclude_disk_quota exclude_graphdriver_btrfs
    exclude_graphdriver_devicemapper exclude_graphdriver_zfs"

As we've already solved in the other docker/moby recipes, we any setting of buildtags needs to be by variable, so it can be overriden by bbappends, etc.

Quoted 8 lines
    +       export DOCKER_LDFLAGS="-s"
    +
    +       VERSION=${BALENA_VERSION} ./hack/make.sh dynbinary-balena

And here we are with the repeated moby build infrastructure.

I am curious as to why mainline moby won't work for this.

I have no idea, but can look into that.

Quoted 10 lines

    +
    +       # Compile mobynit
    +       cd .gopath/src/"${DOCKER_PKG}"/cmd/mobynit
    +       go build -ldflags '-extldflags "-static
    ${MOBYNIT_EXTRA_LDFLAGS}"' .
Quoted 7 lines

This shouldn't be using 'go' directly, at the least, it should be using the variables as defined in the go classes.

But again, this is solving and duplicating all the fixes that we've had to do over time in the existing moby recipe. .. this is less than ideal. and anything that we haven't solved there, we should actually be fixing there.

I will drop the mobynit completely from this recipe. This was actually also done lately in the meta-balena:
https://github.com/balena-os/meta-balena/commit/29844ed3bd936c581e20b72df133a2b6ed498512

Quoted 33 lines

    +       cd -
    +}
    +
    +do_install() {
    +       mkdir -p ${D}/${bindir}
    +       install -m 0755
    ${S}/src/import/bundles/dynbinary-balena/balena-engine
    ${D}/${bindir}/balena-engine
    +       # install -d ${D}/boot
    +       # install -m 0755 ${S}/src/import/cmd/mobynit/mobynit
    ${D}/boot/init
    +       # echo ${BALENA_STORAGE} > ${D}/boot/storage-driver
    +
    +       ln -sf balena-engine ${D}/${bindir}/balena
    +       ln -sf balena-engine ${D}/${bindir}/balenad
    +       ln -sf balena-engine ${D}/${bindir}/balena-containerd
    +       ln -sf balena-engine ${D}/${bindir}/balena-containerd-shim
    +       ln -sf balena-engine ${D}/${bindir}/balena-containerd-ctr
    +       ln -sf balena-engine ${D}/${bindir}/balena-runc
    +       ln -sf balena-engine ${D}/${bindir}/balena-proxy
    +
    +       ln -sf balena-engine ${D}/${bindir}/balena-engine-daemon
    +       ln -sf balena-engine ${D}/${bindir}/balena-engine-containerd
    +       ln -sf balena-engine
    ${D}/${bindir}/balena-engine-containerd-shim
    +       ln -sf balena-engine
    ${D}/${bindir}/balena-engine-containerd-ctr
    +       ln -sf balena-engine ${D}/${bindir}/balena-engine-runc
    +       ln -sf balena-engine ${D}/${bindir}/balena-engine-proxy
Quoted 2 lines

Outside of the branding, what's the difference between these binaries and when we build the upstream project variants ?

I think we only care about the balena-engine for the purpose of this layer, really.
From what I understand, the first ones are used in the balenaOS and I should have dropped them in the initial recipe port.

Quoted 50 lines

    +
    +       install -d ${D}${systemd_unitdir}/system
    +       install -m 0644
    ${S}/src/import/contrib/init/systemd/balena-engine.socket
    ${D}/${systemd_unitdir}/system
    +       install -m 0644
    ${S}/src/import/contrib/init/systemd/balena-engine.service
    ${D}/${systemd_unitdir}/system

The init system is variable, and should be checked before attempting to install services.

    +
    +       install -d ${D}/home/root/.docker
    +       ln -sf .docker ${D}/home/root/.balena
    +       ln -sf .docker ${D}/home/root/.balena-engine

As mentioned above /home/room, shouldn't be hardcoded.

    +
    +       install -d ${D}${localstatedir}/lib/docker

Now we are polluting namespaces. A balena recipe making directories called "docker". This is the issue I had with k3s and CNI, and my concern about all the vendored versions we are getting in the container recipes.

    +       ln -sf docker ${D}${localstatedir}/lib/balena
    +       ln -sf docker ${D}${localstatedir}/lib/balena-engine
    +
    +       install -d ${D}${sysconfdir}/tmpfiles.d
    +       install -m 0644 ${WORKDIR}/balena-tmpfiles.conf
    ${D}${sysconfdir}/tmpfiles.d/
    +}
    +
    +BBCLASSEXTEND = " native"
Quoted 1 line

Where is this being used natively ?

I see no usecase for the purpose of meta-virt.
In case of balenaOS it was used to build the containers probably. Will drop that.

Quoted 21 lines

Bruce

    -- 
    2.25.1
Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
Signature · 4 lines
Maciej Pijanowski
Embedded Firmware Team Leader
GPG: 9963C36AAC3B2B46
https://3mdeb.com | @3mdeb_com